<?php
session_start();

if(!isset($_SESSION['userid']))//检查 userid 是否已经设置，如果没有设置，提示未登录并跳转首页
{
    echo "<script>alert('您尚未登录！')</script>";
    echo "<script>window.location.href='index.php'</script>";

}

$userid=$_SESSION['userid'];
include ('mysqli_connect.php');

//取数据库中user的所有信息
$sqlb="select * from user_table where user_id={$userid} ;";
$resb=mysqli_query($dbc,$sqlb);
$resultb=mysqli_fetch_array($resb);

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>影视管理系统&emsp;密码修改</title>
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        body{
            width: 100%;
            overflow: hidden;
            background: url("300046-106.jpg") no-repeat;
            background-size:cover;
            color: antiquewhite;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">我的影视库</a>
        </div>
        <div>
            <ul class="nav navbar-nav">
                <li><a href="user_index.php">主页</a></li>
                <li><a href="user_querymovie.php">影视查询</a></li>-->
                <li><a href="user_sheet.php">我的收藏</a></li>-->
                <li class="active dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">个人信息<b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="user_info.php">用户信息</a></li>
                        <li><a href="user_repass.php">修改密码</a></li>
                    </ul>
                </li>
                <li><a href="index.php">退出</a></li>
            </ul>
        </div>
    </div>
</nav>



<h1 style="text-align: center"><strong>个人信息修改</strong></h1>
<div style="padding: 10px 500px 10px;">
    <form  action="user_info_edit.php" method="POST" style="text-align: center" class="bs-example bs-example-form" role="form">
        <div id="login">
            <div class="input-group"><span  class="input-group-addon">用户名</span><input value="<?php echo $resultb['user_name']; ?>" name="user_name" type="text" placeholder="请输入修改后的用户名" class="form-control"></div><br/>
            <div class="input-group"><span  class="input-group-addon">性别</span><input value="<?php echo $resultb['user_sex']; ?>" name="user_sex" type="text" placeholder="请输入修改后的性别" class="form-control"></div><br/>
            <div class="input-group"><span  class="input-group-addon">出生年份</span><input value="<?php echo $resultb['user_age']; ?>"  name="user_age" type="text" placeholder="请输入修改后的出生年份" class="form-control"></div><br/>
            <label><input type="submit" value="确认" class="btn btn-default"></label>
            <label><input type="reset" value="重置当前值" class="btn btn-default"></label>
        </div>
    </form>
</div>
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST")
{


    $nnam = $_POST["user_name"];
    $nsex = $_POST["user_sex"];
    $nbirth = $_POST["user_age"];
//    $nadd = $_POST["address"];
//    $nint = $_POST["telcode"];


    $sqla="update user_table set user_name='{$nnam}',user_sex='{$nsex}',user_age='{$nbirth}' where user_id={$userid};";
    $resa=mysqli_query($dbc,$sqla);

//    $sqlc="update reader_card set name='{$nnam}' where reader_id={$userid};";
//    $resc=mysqli_query($dbc,$sqlc);
//    if($resa==1&&$resc==1)
    if($resa==1)
    {

        echo "<script>alert('修改成功！')</script>";
        echo "<script>window.location.href='user_info.php'</script>";

    }
    else
    {
        echo "<script>alert('修改失败！请重新输入！');</script>";

    }

}


?>
</body>
</html>
